package com.attunlcok.unlock.controller;

import com.attunlcok.common.annotation.Log;
import com.attunlcok.common.core.controller.BaseController;
import com.attunlcok.common.core.domain.AjaxResult;
import com.attunlcok.common.core.page.TableDataInfo;
import com.attunlcok.common.enums.BusinessType;
import com.attunlcok.common.utils.poi.ExcelUtil;
import com.attunlcok.unlock.domain.AttEmailInfo;
import com.attunlcok.unlock.service.IAttEmailInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ATT邮箱信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/unlock/AttEmailInfo")
public class AttEmailInfoController extends BaseController
{
    private String prefix = "unlock/AttEmailInfo";

    @Autowired
    private IAttEmailInfoService attEmailInfoService;

    @RequiresPermissions("unlock:AttEmailInfo:view")
    @GetMapping()
    public String email()
    {
        return prefix + "/AttEmailInfo";
    }

    /**
     * 查询ATT邮箱信息列表
     */
    @RequiresPermissions("unlock:AttEmailInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AttEmailInfo attEmailInfo)
    {
        startPage();
        List<AttEmailInfo> list = attEmailInfoService.selectAttEmailInfoList(attEmailInfo);
        return getDataTable(list);
    }

    /**
     * 导出ATT邮箱信息列表
     */
    @RequiresPermissions("unlock:AttEmailInfo:export")
    @Log(title = "ATT邮箱信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AttEmailInfo attEmailInfo)
    {
        List<AttEmailInfo> list = attEmailInfoService.selectAttEmailInfoList(attEmailInfo);
        ExcelUtil<AttEmailInfo> util = new ExcelUtil<AttEmailInfo>(AttEmailInfo.class);
        return util.exportExcel(list, "ATT邮箱信息数据");
    }

    /**
     * 新增ATT邮箱信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存ATT邮箱信息
     */
    @RequiresPermissions("unlock:AttEmailInfo:add")
    @Log(title = "ATT邮箱信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AttEmailInfo attEmailInfo)
    {
        return toAjax(attEmailInfoService.insertAttEmailInfo(attEmailInfo));
    }

    /**
     * 修改ATT邮箱信息
     */
    @RequiresPermissions("unlock:AttEmailInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AttEmailInfo attEmailInfo = attEmailInfoService.selectAttEmailInfoById(id);
        mmap.put("attEmailInfo", attEmailInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存ATT邮箱信息
     */
    @RequiresPermissions("unlock:AttEmailInfo:edit")
    @Log(title = "ATT邮箱信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AttEmailInfo attEmailInfo)
    {
        return toAjax(attEmailInfoService.updateAttEmailInfo(attEmailInfo));
    }

    /**
     * 删除ATT邮箱信息
     */
    @RequiresPermissions("unlock:AttEmailInfo:remove")
    @Log(title = "ATT邮箱信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(attEmailInfoService.deleteAttEmailInfoByIds(ids));
    }

    /**
     * 批量导入邮箱信息
     */
    @RequiresPermissions("unlock:AttEmailInfo:import")
    @Log(title = "ATT邮箱信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(String emailData)
    {
        String operName = getLoginName();
        String message = attEmailInfoService.importEmailData(emailData, operName);
        return success(message);
    }
}
